﻿// YamlScalarAttribute.cs
//
// Copyright 2008 by Burt Harris
// Licensed under the Microsoft Public License (Ms-PL)
// See: http://www.codeplex.com/yaml/license
//

using System;

namespace YaTools.Yaml
{
    /// <summary>
    /// Indicates a class should be serialized as a scalar value determined
    /// by ToString() and deserialized by calling a single-argument 
    /// string constructor.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
    public sealed class YamlScalarAttribute : Attribute
    {
        public static readonly YamlScalarAttribute No
            = new YamlScalarAttribute(false);

        public static readonly YamlScalarAttribute Yes
            = new YamlScalarAttribute(true);

        public static readonly YamlScalarAttribute Default
            = No;

        private readonly bool _active;

        public YamlScalarAttribute() : this(true)
        {
        }

        public YamlScalarAttribute(bool active)
        {
            _active = active;
        }

        public bool Active
        {
            get { return _active; }
        }

        public override bool Equals(object obj)
        {
            if (obj == this) return true;
            var other = obj as YamlScalarAttribute;
            return (other != null && other._active == _active);
        }

        public override int GetHashCode()
        {
            return _active.GetHashCode();
        }
    }
}